package com.quanyan.ic.datacenter.dao.impl;

import com.quanyan.ic.datacenter.dao.PlaceUnitVideoAlarmDao;
import com.quanyan.ic.datacenter.mapper.icData.PlaceUnitVideoAlarmMapper;
import com.quanyan.ic.datacenter.mapper.icData.entity.PlaceUnitVideoAlarm;
import com.quanyan.ic.datacenter.mapper.icData.entity.PlaceUnitVideoAlarmExample;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by zhuo.shi on 2017/8/28.
 */
@Repository
public class PlaceUnitVideoAlarmDaoImpl implements PlaceUnitVideoAlarmDao {

    @Autowired
    private PlaceUnitVideoAlarmMapper placeUnitVideoAlarmMapper;

    @Override
    public PlaceUnitVideoAlarm exist(Integer alarmUuid) {
        PlaceUnitVideoAlarmExample example = new PlaceUnitVideoAlarmExample();
        example.createCriteria().andAlarmUuidEqualTo(alarmUuid);
        List<PlaceUnitVideoAlarm> alarmList = placeUnitVideoAlarmMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(alarmList)){
            return null;
        }
        return alarmList.get(0);
    }

    @Override
    public void insertPlaceUnitVideoAlarm(PlaceUnitVideoAlarm alarm) {
        placeUnitVideoAlarmMapper.insertSelective(alarm);
    }

    @Override
    public void updatePlaceUnitVideoAlarm(PlaceUnitVideoAlarm alarm) {
        placeUnitVideoAlarmMapper.updateByPrimaryKeySelective(alarm);
    }
}
